package com.sgb.jicai.view.adapter;


import android.content.Context;
import android.widget.TextView;

import com.sgb.jicai.BR;
import com.sgb.jicai.R;
import com.sgb.jicai.databinding.ItemFactoryParticipationPriceRoleChildListBinding;
import com.sgb.jicai.entity.FactoryParticipationEntity;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;
import java.util.List;

/**
 * 供方发起-立即参与页面--采购清单列表 -- 子列表价格规则列表适配器
 */
public class FactoryParticiShoppingChildListAdapter extends BaseRecycleAdapter<FactoryParticipationEntity.PriceRolesEntity> {

    private String unitNme = "";
    private Context context;

    /*
    public FactoryParticiShoppingChildListAdapter(Context context, List<FactoryParticipationEntity.PriceRolesEntity> datas) {
         super(context, R.layout.item_factory_participation_price_role_child_list, datas);
     }
 */
    public FactoryParticiShoppingChildListAdapter(Context context, List<FactoryParticipationEntity.PriceRolesEntity> datas, String unitNme) {
        super(context, R.layout.item_factory_participation_price_role_child_list, datas);
        this.context = context;
        this.unitNme = unitNme;
    }

    @Override
    public void convert(ItemViewHolder holder, FactoryParticipationEntity.PriceRolesEntity priceRoleEntity) {
        holder.setBinding(BR.viewModel, priceRoleEntity);
        ((ItemFactoryParticipationPriceRoleChildListBinding) holder.getmBinding()).tvUnitname.setText(unitNme);

        updatViewColor(((ItemFactoryParticipationPriceRoleChildListBinding) holder.getmBinding()).tvNum, priceRoleEntity);
        updatViewColor(((ItemFactoryParticipationPriceRoleChildListBinding) holder.getmBinding()).tvUnitname, priceRoleEntity);
        updatViewColor(((ItemFactoryParticipationPriceRoleChildListBinding) holder.getmBinding()).tvPrice, priceRoleEntity);
    }

    private void updatViewColor(TextView textView, FactoryParticipationEntity.PriceRolesEntity entity) {
        switch (entity.getPriceWarning()) {//价格预警 1 大于 2 等于 3 小于
            case 1:
                textView.setTextColor(context.getResources().getColor(R.color.color_FF4B10));
                break;
            case 2:
                textView.setTextColor(context.getResources().getColor(R.color.new_blue));
                break;
            case 3:
                textView.setTextColor(context.getResources().getColor(R.color.color_06C764));
                break;
            default:
                textView.setTextColor(context.getResources().getColor(R.color.new_blue));
                break;
        }
    }

    @Override
    public int getItemCount() {
        if (getDatas() != null && getDatas().size() > 0) {
            return getDatas().size();
        }
        return 0;
    }
}
